package com.cctv.ldap;

import java.io.Serializable;

import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.support.AbstractContextMapper;

/**
 * 
 * @author 146
 * 
 */
public class LdapDept implements Serializable {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 7597468203919362785L;

	private long				id;

	private String				ou;										// 无意义码

	private String				description;							// 部门描述

	private String				postalcode;								// 旧的层次码
	
	// 下面两个属性暂时没加上
	private String				postalAddress;							// 部门级别
	private String				postOfficeBox;							// 父级部门
	private String				street;									// 所属系统

	public String getOu() {
		return ou;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public void setOu(String ou) {
		this.ou = ou;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getPostalcode() {
		return postalcode;
	}

	public void setPostalcode(String postalcode) {
		this.postalcode = postalcode;
	}

	/**
	 * @return the postalAddress
	 */
	public String getPostalAddress() {
		return postalAddress;
	}

	/**
	 * @param postalAddress
	 *            the postalAddress to set
	 */
	public void setPostalAddress(String postalAddress) {
		this.postalAddress = postalAddress;
	}

	/**
	 * @return the postOfficeBox
	 */
	public String getPostOfficeBox() {
		return postOfficeBox;
	}

	/**
	 * @param postOfficeBox
	 *            the postOfficeBox to set
	 */
	public void setPostOfficeBox(String postOfficeBox) {
		this.postOfficeBox = postOfficeBox;
	}

	/**
	 * @return the street
	 */
	public String getStreet() {
		return street;
	}

	/**
	 * @param street
	 *            the street to set
	 */
	public void setStreet(String street) {
		this.street = street;
	}

	private  static final class DeptContextMapper extends AbstractContextMapper {
		protected Object doMapFromContext(DirContextOperations ctx) {
			LdapDept dept = new LdapDept ();
			dept.setOu ( ctx.getStringAttribute ( "ou" ) );
			dept.setDescription ( ctx.getStringAttribute ( "description" ) );
			dept.setPostalcode ( ctx.getStringAttribute ( "postalcode" ) );
			dept.setPostalAddress ( ctx.getStringAttribute ("postalAddress" ));
			dept.setPostOfficeBox ( ctx.getStringAttribute("postOfficeBox") );
			dept.setStreet ( ctx.getStringAttribute("street" ));
			return dept;
		}
	}
	

	protected static ContextMapper getMapper() {

		return new DeptContextMapper ();
	}
	
	public static final String[]	ATTRIBUTES	= new String[] { "ou", "description","postalcode", "postalAddress", "postOfficeBox","street",};
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return "LdapDept [id=" + id + ", ou=" + ou + ", description=" + description + ", postalcode=" + postalcode + ", postalAddress=" + postalAddress + ", postOfficeBox=" + postOfficeBox
				+ ", street=" + street + "]";
	}
	
}
